package com.boot.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UploadController {

    @RequestMapping("/upload")
    public Map<String,Object> upload(MultipartFile myFile, String userName, String password) throws IOException {
        String fileName = myFile.getOriginalFilename();
        //upload/image/photo/xxx.jpg
        //图片服务器的地址+数据库中相对路径地址
        String toFolder = "c:/aServer/";

        myFile.transferTo(new File(toFolder+fileName));

        Map<String,Object> map = new HashMap<>();
        map.put("fileName",fileName);
        return map;
    }

}
